﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

   public class Deck
    {
        private List<Card> _cards;
        private Random random = new Random();

        public Deck()
        {
            _cards = new List<Card>();
            for (int suit = 0; suit <= 3; suit++)
                for (int value = 1; value <= 13; value++)
                    _cards.Add(new Card((CardSuit)suit, (CardRank)value));
        }

        public Card dealCard()
        {
            //TODO check that there are cards
            var card = _cards.First();
            _cards.RemoveAt(0);
            return card;
        }

        public Card getCard(int cardPosition)
        {
            //TODO check bounds for card position
            var card = _cards.ElementAt(cardPosition);
            _cards.RemoveAt(cardPosition);
            return card;
        }

        public void Shuffle()
        {
            List<Card> newCards = new List<Card>();
            while (_cards.Count > 0)
            {
                int CardToMove = random.Next(_cards.Count);
                newCards.Add(_cards[CardToMove]);
                _cards.RemoveAt(CardToMove);
            }
            _cards = newCards;
        }

        public Card Deal()
        {
            return getCard(0);
        }

    }
